/**
 * Copyright (C) 2006 ChangSha WangWin Science & Technology CO,.LTD. All rights reserved.
 * WangWin PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

package com.kingcore.pda.core.listener;

import java.sql.Connection;
import java.sql.Statement;
import java.util.Date;
import java.util.HashMap;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.apache.log4j.Logger;

/**
 * <p>用户会话监听器类。</p>
 * @author Zeven on 2007-2-11
 * @version	1.0
 * @see		Object#equals(java.lang.Object)
 * @see		Object#hashCode()
 * @see		HashMap
 * @since	JDK5
 */

public class UserSessionListener implements HttpSessionListener  {
	
	Logger log = Logger.getLogger( this.getClass() );
	/**
	 * Method sessionCreated
	 *
	 *
	 * @param event
	 *
	 */
	public void sessionCreated(HttpSessionEvent event) {
		//System.out.println ("session begin!");	
		java.text.SimpleDateFormat sdf =new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		Date date = new Date();
		String strNow=sdf.format( date );

		long time = event.getSession().getCreationTime();
		date.setTime( time );
		String strCreate = sdf.format( date );
		
		log.debug ("session sessionCreated at "+ strCreate + " ,now is " + strNow);
	
	}
	
	/**
	 * Method sessionDestroyed
	 *
	 *
	 * @param event
	 *
	 */
	public void sessionDestroyed(HttpSessionEvent event){
		//System.out.println ("session end!");
		
		Connection conn=null;
		Statement stmt=null;
		String sql;
		
		try{

			//System.out.println ("session begin!");	
			java.text.SimpleDateFormat sdf =new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			
			Date date = new Date();
			String strNow=sdf.format( date );

			long time = event.getSession().getCreationTime();
			date.setTime( time );
			String strCreate = sdf.format( date );
			
			log.debug ("sessionDestroyed! session sessionCreated at "+ strCreate + " ,now is " + strNow);
					
		}catch(Exception e){
			System.out.println (""+e.getMessage());
		}finally{
			try{
				if(stmt!=null){
					stmt.close();
				}
				if(conn!=null){
					conn.close();
				}
			}catch(java.sql.SQLException e){
				System.out.println ("关闭连接错误"+e.getMessage());
			}
		}
		
	}	
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
	}
	
}
